<?php

class objName{
	
	
	
	function variant_report($type_of, $id,$data){
		
		
		
	
	}
	
	function datadelete($tbl,$field,$pid){
		$query = "Delete FROM ".$tbl." where ".$field." ='".$pid."' "; 
		$result = mysql_query($query)or die(mysql_error());;
		if(mysql_affected_rows()){
			return true;
		}
		else{
			return false;
		}
	}
	
			
	function brandindb($brand){
	
			$result=mysql_query("select categories,brand from tbltradein where id='$brand' and categories= 'auto' and display ='1' ") or die("select name from tblmodel where id=$brand"."<br/><br/>".mysql_error());
			$row=mysql_fetch_array($result);
			if(mysql_num_rows($result)<1){
				return true;
			}else{
			return false;
			}
	}
	
	
	function get_product_brand($brand){
	
			$result=mysql_query("select brand from tblbrand where id='$brand'") or die("select name from tblmodel where id=$brand"."<br/><br/>".mysql_error());
			$row=mysql_fetch_array($result);
			return $row['brand'];
	}
	
	function ismodelexist($model,$brandid){
		//$model = strtoupper($model);
		//$brandid = strtoupper($brandid);
		
		$result=mysql_query("SELECT brandId,modelname FROM tblmodel WHERE brandId ='$brandid' AND modelname LIKE '$model%' ")or die(mysql_error());
		//echo $result;
		if(mysql_affected_rows()){
			return "merun";
		}
		else{
			return false;
		}
	}
	function ismodelexist2($model){
		//$model = strtoupper($model);
		//$brandid = strtoupper($brandid);
		
		$result=mysql_query("SELECT modelname FROM tblmodel WHERE modelname = '$model' ")or die(mysql_error());
		//echo $result;
		if(mysql_affected_rows()){
			return "merun";
		}
		else{
			return false;
		}
	}
	function isbrandexist($brand){
		$brand = strtoupper($brand);
		$result = mysql_query("SELECT brand FROM tblbrand where brand LIKE '$brand%' ")or die(mysql_error());
		if(mysql_affected_rows()){
			return "merun";
		}
		else{
			return false;
		}
	
	}
	
	function ispartsexist($parts){
		$parts = strtoupper($parts);
		$result = mysql_query("SELECT parts FROM tblparts where parts LIKE '$parts%' ")or die(mysql_error());
		if(mysql_affected_rows()){
			echo "merun";
		}
		else{
			echo false;
		}
	
	}
	function addmodel($model,$brandid){
		$model = strtoupper($model);
		$brandid = strtoupper($brandid);
		$model = mysql_real_escape_string(htmlentities(trim($model)));
		$brandid =  mysql_real_escape_string(htmlentities(trim($brandid)));
		
		$result=mysql_query("INSERT INTO tblmodel(brandId,modelname)values('$brandid','$model') ")or die(mysql_error());
		//echo $result;
		if(mysql_affected_rows()){
			return "merun";
		}
		else{
			return false;
		}
	}
	function addbrand($brand){
		$brand = strtoupper($brand);
		$brand = mysql_real_escape_string(htmlentities(trim($brand)));
		$result = mysql_query("INSERT INTO tblbrand(brand)values('$brand') ")or die(mysql_query());
		if(mysql_affected_rows()){
			return "merun";
		}
		else{
			return false;
		}
	
	}
	
	function addparts($parts){
		$parts = strtoupper($parts);
		$parts = mysql_real_escape_string(htmlentities(trim($parts)));
		$result = mysql_query("INSERT INTO tblparts(parts)values('$parts') ")or die(mysql_error());
		if(mysql_affected_rows()){
			echo "merun";
		}
		else{
			echo false;
		}
	
	}
	
	
	function get_profile_name($name){
				
			$result=mysql_query("select fname,lname from tbl_account where id='$name'") or die("select fname,lname from tbl_account where id=$name"."<br/><br/>".mysql_error());
			$row=mysql_fetch_array($result);
			return $row['fname']." ".$row['lname'] ;
	}
	function get_vcode($codeid,$code){
		$result=mysql_query("select id,code from tbl_account where id='$codeid'") or die("select isaprove from tbl_account where id=$codeid"."<br/><br/>".mysql_error());
		$row=mysql_fetch_array($result);
		if($code == $row['code']){
			return $row['code'];
		}
		else{
			return false;
		}
	
	}
	
	function create_query($tblname,$tblfield,$get){
		
		$sql = "SELECT * FROM $tblname where $tblfield like '$get%' AND categories LIKE 'AUTO%' AND conditions like 'BrandNew%' ORDER BY id DESC";
		
		$display = "";
		$from = "cars";
		$on = true;
		$result = mysql_query($sql)or die("</br>".mysql_error());
		$count = mysql_num_rows($result);
		
		if($count <= 0){
			
			echo '<div style="margin-top:10px;"><h3 style="color:white;">No Item Found</h3></div>';
			
		}
		else{
			while($row = mysql_fetch_array($result)){
				if($on){
				$display .= '<div class="boxgrid slideright" id="holdershop">';
					$on = false;
				}
				else if($on){
				$display .= '<div class="boxgrid thecombo" id="holdershop">';
					$on="";
				}
				else{
				$display .= '<div class="boxgrid slidedown" id="holdershop">';
					$on = true;
				}
				$data = array();
				$data = explode("+",$row['filename']);
					if(is_array($data)){
						$imgko = $data[0];
					}
				$display .= '<img class="cover" id="imgshop" src="images/vehicles/'.$imgko.'"/>';
				$display .= '<h3 style="color:red;" align="center">'.$row['name'].'</h3>';
					$display .= '<div class="description">';
						$display .= '<label>Brand: </label>';
						$display .= '<label>'.$row["brand"].'</label>';
						$display .= '<br/>';
						$display .= '<label>Model: </label>';
						$display .= '<label>'.$row['model'].'</label>';
						$display .= '<br/>';
						$display .= '<label>Condition: </label>';
						$display .= '<label>'.$row['conditions'].'</label>';
						$display .= '<br/>';
						$display .= '<label>Transmission: </label>';
						$display .= '<label>'.$row['transmission'].'</label>';
						$display .= '<br/>';
						$display .= '<label>Fuel: </label>';
						$display .= '<label>'.$row['fuel'].'</label>';
						$display .= '<br/>';
						$display .= '<label>Price: </label>';
						$display .= '<label>P '.$row['price'].'</label>';
						$display .= '<br/>';
						$display .= '<a href="preview.php?from='.$from.'&pageid='.trim($row['id']).'" >see more</a>';
						$display .= '<input type="hidden" value="'.$row['id'].'" id="'.$row['id'].'">';
					$display .= '</div>';
				$display .= '</div>';
				
			}
			return $display;
		}
		
	}
	
	function displayimg($image,$count){
		$imgArr = array();
		$imgArr = explode("+",$image);
		$m ="";
		if($count){
			return $imgArr[0];
		}
		else{
			$x = count($imgArr);
			
			for($i=0; $i<$x-1; $i++){
			$m .='<img src="images/vechicles/'.$imgArr[$i].'" />';
			}
			return $m;
		}
	}
	
	
	
	
	
}
?>